package com.hyh.music.mapper;

import com.github.pagehelper.Page;
import com.hyh.music.domain.domainDTO.SearchDTO;
import com.hyh.music.domain.domainDTO.SongPageDTO;
import com.hyh.music.domain.domains.ListSong;
import com.hyh.music.domain.domains.Song;
import com.hyh.music.domain.domianVO.SearchVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author hyh
 * @version 1.0
 */
@Mapper
public interface SongMapper {

    /**
     * 歌曲的分页查询
     * @param songPageDTO
     * @return
     */
    Page<Song> page(SongPageDTO songPageDTO);

    /**
     * 添加歌曲
     * @param song
     */
    @Insert("insert into song (singer_id, name, album, create_time, update_time, image, lyric ,url , musictotaltime) " +
            "values ( #{singerId}, #{name},#{album},#{createTime},#{updateTime},#{image},#{lyric},#{url},#{musictotaltime})")
    void addSong(Song song);

    /**
     * 根据id查询歌曲
     * @param id
     * @return
     */
    @Select("select * from song where id = #{id}")
    Song selectById(@Param("id") Integer id);

    /**
     * 更新歌曲
     * @param song
     */
    void update(Song song);

    /**
     * 删除歌曲
     * @param id
     */
    @Delete("delete from song where id = #{id}")
    void deleteById(Integer id);

    /**
     * 查询歌手歌曲
     * @param id
     * @return
     */
    @Select("select * from song where singer_id = #{id}")
    List<Song> selectBySingerId(Integer id);

    /**
     * 搜索所有歌曲
     * @return
     */
    @Select("select * from song")
    List<Song> selectAllSongs();

    /**
     * 查询是否有重复的
     * @param songId
     * @param id
     * @return
     */
    @Select("select * from list_song where song_list_id = #{id} and song_id = #{songId}")
    List<ListSong> selectIfRepeat(@Param("songId") Integer songId,@Param("id") Integer id);

    /**
     * 默认搜索
     * @param searchDTO
     * @return
     */
    Page<SearchVO> select(SearchDTO searchDTO);
}
